<?php
namespace app\index\controller;

use app\index\model\Users;
use think\Db;
use app\index\model\Job;
use app\common\controller\IndexBase;


class Index extends IndexBase
{
    public function search_jl()
    {   
        return $this->fetch('search_jl');
    }
    public function index()
    {

        $openid = session('wx');
//        halt($openid);
        $res = model('jianlis')->where('openid',$openid)->count();
        $res1 = model('jianlisqz')->where('openid',$openid)->count();
        if ($res || $res1) {
            return $this->usercenter();
        }else{
            return $this->fetch('search_jl');
        }   
    }
    public function usercenter()
    {   
        $openid = session('wx');
        $user_data = db("users")->where(['openid'=>$openid])->find();
        $user_data['count'] = db('users')->where(['otuijian'=>$user_data['tuijian']])->count();
        // halt($user_data);
        return $this->fetch('usercenter',['user_data'=>$user_data]);       
    }
    public function send()
    {   
        $toudi_arr = db('toudi')->where('openid',session('wx'))->column('jobid');
        $zw_lsit = model('job')->where('jobid','in',$toudi_arr)->field('jobid,cid,jobname,wage,city,is_index,update_time,reading')->order('is_index desc,sort desc,update_time desc,add_time desc,jobid desc')->select();
        if ($zw_lsit) {
            $this->assign('zw_lsit',$zw_lsit);
        }else{
            $this->assign('zw_lsit','');
        }
        return $this->fetch('send');
    }
    public function otuijian()
    {
        $openid = session('wx');
        $tuijian = db("users")->where(['openid'=>$openid])->value('tuijian');
        if($tuijian==NULL){
            $user_list=array();
        }else{
            $user_list = db('users')->where(['otuijian'=>$tuijian])->column('name');
        }


        return $this->fetch('otuijian',['user_list'=>$user_list]);       
    }

    public function qrcode()
    {
        $user = new Users();
        $userData = $user->where(['openid'=>session('wx')])->find();
        return $this->fetch('qrcode',['userData'=>$userData]);
    }
}